<?php
namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\Rakuten\RakutenLogs;
class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule){

        if (file_exists('rakuten.txt')) { //rakuten.txt(标识文件)

            /** (5分钟)**/
            /** (gucang)(海外仓-谷仓相关计划任务（请勿更改或删除）)**/
            //谷仓入库订单同步 （谷仓入库单,回写至erp海外仓(代发)库存）
            //$schedule->command('gucang:get-grn-detail')->everyFiveMinutes()->runInBackground()->description('SyncInboundOrder');
            //谷仓入库订单同步 （谷仓库存，实时同步erp海外仓(代发)库存）
            $schedule->command('gucang:get_product_inventory')->everyFiveMinutes()->runInBackground()->description('SyncProductInventory');
            //同步sku库存至乐天平台（同步库存,(FBA、海外仓)库存回传至Rakuten平台.）
            $schedule->command('rakuten:sync-rakuten-inventory')->everyFiveMinutes()->unlessBetween('05:00', '07:00')->runInBackground()->description('syncRakutenInventory');
            //同步物流追踪号 (erp订单物流同步至Rakuten平台,向乐天平台回传erp订单物流追踪号.）
            $schedule->command('rakuten:sync-rakuten-order-tracking-no')->everyFiveMinutes()->runInBackground()->description('syncRakutenOrderTrackingNo');


            /** (rakuten)日本乐天平台相关计划任务（请勿更改或删除） start **/
            //乐天订单同步 （同步Rakuten-API订单至基础数据库）
            $schedule->command('rakuten:get-rakuten-orders')->everyFiveMinutes()->runInBackground()->description('getRakutenOrder');
            //rakuten订单同步至ERP（将未同步的rakuten订单同步至ERP）
            $schedule->command('rakuten:sync-rakuten-order')->everyFiveMinutes()->runInBackground()->description('syncRakutenOrder');
            //erp异常订单 (rakuten基础数据同步至erp后台数据库,匹配失败的异常订单.)
            $schedule->command('rakuten:sync-rakuten-order-exception')->everyFiveMinutes()->runInBackground()->description('syncRakutenOrderException');
            /** (rakuten)日本乐天平台相关计划任务（请勿更改或删除） end **/


            /** (shopify)独立站平台相关计划任务（请勿更改或删除） start **/
            //乐天订单同步 （同步shopify-API订单至基础数据库）
            $schedule->command('shopify:get-shopify-orders')->everyFiveMinutes()->runInBackground()->description('getShopifyOrder');
            //erp订单同步 （shopify基础数据同步至erp后台数据库）
            $schedule->command('shopify:sync-shopify-orders')->everyFiveMinutes()->runInBackground()->description('syncShopifyOrder');
            //erp异常订单 (shopify基础数据同步至erp后台数据库, 匹配失败的异常订单.)
            $schedule->command('shopify:sync-shopify-orders-exception')->everyFiveMinutes()->runInBackground()->description('syncShopifyOrderException');
            //同步物流追踪号 (erp订单物流同步至shopify平台, 向独立站平台回传erp订单物流追踪号.）
            //$schedule->command('shopify:sync-shopify-order-tracking-no')->everyFiveMinutes()->runInBackground()->description('syncShopifyOrderTrackingNo');
            /** (shopify)独立站平台相关计划任务（请勿更改或删除） end **/

        }

        if (!file_exists('rakuten.txt')) { //非Rakuten平台命令（rakuten.txt(标识文件)）
            //$schedule->command('sp-order:get-orders')->cron('*/5 3-23 * * *')->runInBackground()
            //    ->description('getOrders');

            //erp未发货的客户订单(发货方式)
            $schedule->command('erp-order:sync-customer-order')->hourlyAt(1)->runInBackground()->description('syncCustomerOrder');
            //erp发货单异常(超时的发货订单)
            $schedule->command('erp-order:error-customer-order')->dailyAt('00:01')->runInBackground()->description('deliveryOrderException');

            ////客户发货单（上传客户发货单至Amazon）
            //$schedule->command('amazon:create-fulfillment-order')->hourlyAt(3)->description('syncCreateAmazonOrder'); //每日
            //客户发货单物流追踪号(Amazon)（自动,获取Amazon物流号）
            $schedule->command('amazon:get-outbounds')->hourlyAt(53)->description('syncAmazonTrackingNo'); //每日

            //客户发货单（上传客户发货单至Rakuten海外仓(谷仓)）
            $schedule->command('rakuten:create-overseas-order')->hourlyAt(7)->description('syncCreateRakutenOrder'); //每日
            //客户发货单物流追踪号(Rakuten)（自动,获取海外仓物流号）
            $schedule->command('rakuten:update-order-info')->hourlyAt(56)->description('syncRakutenGuCangTrackingNo'); //每日

            //创建Amazon退货报告(每月2号)
            $schedule->command('sp-report:fulfillment-customer-returns')->monthlyOn(2, '01:01')
                ->description('GrabOutbound');
            //获取Amazon退货报告(每月2号)
            $schedule->command('sp-report:get-report GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA')->monthlyOn(2, '01:31')
                ->description('GrabOutbound');
            //解析Amazon退货报告(每月2号)
            $schedule->command('sp-report:parse-fulfillment-customer-returns')->monthlyOn(2, '02:01')
                ->description('GrabOutbound');


            ///********FBA start**********/
            ////一.创建FBA报告
            //$schedule->command('sp-report:reserved-inventory')->hourly()
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiCreateReport'); //fba保留库存
            //$schedule->command('sp-report:myi-inventory')->hourly()
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiCreateReport'); //fba每日库存
            //$schedule->command('sp-report:fulfillment-removal-detail')->fridays()->at('05:10')
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiCreateReport'); //fba移库订单 (周五执行)
            //
            ////二.获取FBA报告
            //$schedule->command('sp-report:get-report')->hourlyAt(20)->description('apiGetReport'); //每日
            //
            ////三.解析FBA报告
            //$schedule->command('sp-report:parse-reserved-inventory')->hourlyAt(40)
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiDownloadDocument'); //fba保留库存
            //$schedule->command('sp-report:parse-myi-inventory')->hourlyAt(41)
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiDownloadDocument'); //fba每日库存
            //$schedule->command('sp-report:parse-fulfillment-removal-detail')->fridays()->at('06:40')
            //    ->unlessBetween('00:00','06:00')->runInBackground()->description('apiDownloadDocument'); //fba移库订单 (周五执行)
            //
            ////FBA库存报告(FBA-JP、UK站点)(每小时执行)
            ////$schedule->command('sp-report:reserved-inventory')->hourlyAt(1)->unlessBetween('00:00','07:00')->description('apiCreateReport'); //每日
            ////$schedule->command('sp-report:create-myi-inventory-jp')->hourlyAt(2)->unlessBetween('00:00','07:00')->description('getReportData'); //每日
            ////$schedule->command('sp-report:create-myi-inventory-uk')->hourlyAt(3)->unlessBetween('00:00','07:00')->description('getReportData'); //每日
            ////
            ////$schedule->command('sp-report:parse-reserved-inventory')->hourlyAt(21)->unlessBetween('00:00','07:00')->description('apiDownloadDocument'); //每日
            ////$schedule->command('sp-report:get-parse-myi-inventory-jp')->hourlyAt(22)->unlessBetween('00:00','07:00')->description('getAndParseReportData'); ////每日
            ////$schedule->command('sp-report:get-parse-myi-inventory-uk')->hourlyAt(23)->unlessBetween('00:00','07:00')->description('getAndParseReportData'); ////每日
            ///********FBA end**********/
            //
            //
            ///********business start**********/
            ////（一）创建business报告
            //$schedule->command('sp-report:create-business')->dailyAt('07:00')->description('SalesAndTraffic');
            ////（二）获取并解析business报告
            //$schedule->command('sp-report:get-parse-business')->dailyAt('07:45')->description('SalesAndTraffic');
            //$schedule->command('sp-report:get-parse-business-repeat')->everyThirtyMinutes()->between('10:00', '14:00')->description('SalesAndTrafficRepeat');
            //
            ////批量创建business报告
            ////$schedule->command('business:batch-create-report')->everyThirtyMinutes()->between('01:00', '08:00')->description('createReportData');
            ////获取并解析business报告
            ////$schedule->command('business:batch-get-parse-report')->hourly()->between('01:00', '08:00')->description('batchGetAndParseReportData');
            ///********business end**********/
            //
            //
            ///********ads start**********/
            ////（一）创建ads报告
            //$schedule->command('ads:create-report')->dailyAt('08:10')->description('CreateAdsReport'); //每日
            ////（二）获取并解析ads报告
            //$schedule->command('ads:get-parse-report')->dailyAt('09:00')->description('GetParseAdsReport'); //每日
            ///********ads end**********/
            ////批量同步收支明细报告（自动）
            ////$schedule->command('sp-report:ledger-detail-view-test')->daily()->description('AmazonReportConditionTest'); //每天执行一次
            //

            /** erp库存 (Amazon库存基础数据同步至erp后台数据库) start **/
            //FBA每日库存报表
            $schedule->command('fab:inventory')->hourlyAt(31)->runInBackground()->description('SrFBAInventory');
            //更新,基础备货站点sku的FBA库存（站点）
            $schedule->command('ss:fab-stock')->hourlyAt(32)->runInBackground()->description('FbaStock');
            //更新,基础备货国家sku的FBA库存（EU国家）
            $schedule->command('country:fba-stock')->hourlyAt(33)->runInBackground()->description('CountryFBAStock');
            //更新,基础备货JPsku的FBA库存 （JP平台）
            $schedule->command('jp:fba-stock')->hourlyAt(34)->runInBackground()->description('JpFBAStock');
            //更新日销量统计报表(SKU)FBA库存
            $schedule->command('sv:fab-stock')->hourlyAt(36)->runInBackground()->description('SVFbaStock');
            //更新日销量统计报表(品类)FBA库存
            $schedule->command('svc:fab-stock')->hourlyAt(38)->runInBackground()->description('SVCFbaStock');
            //（每周五执行）erp-同步移库订单明细
            $schedule->command('os-in:sync-removal-od')->fridays()->at('06:50')->runInBackground()->description('SyncRemovalOrderDetail');
            /** erp库存 (Amazon库存基础数据同步至erp后台数据库) end **/


            /** erp广告 (ads广告基础数据同步至erp后台数据库) start **/
            //产品广告
            $schedule->command('operation:sync-ads-spap')->dailyAt('10:00')->runInBackground()->description('SpAdvertisedProduct');
            //品牌广告
            $schedule->command('operation:sync-ads-sbc')->dailyAt('10:05')->runInBackground()->description('SbCampaigns');
            //展示广告
            $schedule->command('operation:sync-ads-sdap')->dailyAt('10:10')->runInBackground()->description('SdAdvertisedProduct');
            //电视广告
            $schedule->command('operation:sync-ads-stc')->dailyAt('10:15')->runInBackground()->description('StCampaigns');

            //ads异常广告数据同步
            //$schedule->command('ads:sync:ads-error')->daily()->description('AdsError');
            /** erp广告 (ads广告基础数据同步至erp后台数据库) end **/

            //Minute
            //销量、销售额统计报表（平台）
            //统计各平台订单销量到基础销量表
            $schedule->command('sa:volume')->dailyAt('08:06')->runInBackground()->description('volume');    /**（销量1）（平台日销售量）**/ /*------（按天统计销量 平台）-------**/
            $schedule->command('sa:volume-month')->dailyAt('08:09')->runInBackground()->description('volumeMonth');    /**（销量1-1）（平台月销售量）**/
            $schedule->command('sa:amount')->dailyAt('08:13')->runInBackground()->description('amount'); /**（销量2）（平台日销售额）**/
            $schedule->command('sa:amount-month')->dailyAt('08:16')->runInBackground()->description('amountMonth'); /**（销量3）（平台月销售额） **/

            //销量统计报表（ERP）
            $schedule->command('sr:cdsv')->dailyAt('08:21')->runInBackground()->description('csvDaily'); /**（销量4） (erp日销售量) **/    /*------（按天统计销量 erp）------**/
            $schedule->command('sr:dsv')->dailyAt('08:26')->runInBackground()->description('svDaily');   /**（销量5） (erp近30天销售量（SKU）) **/
            $schedule->command('sr:dsv-c')->dailyAt('08:36')->runInBackground()->description('svcDaily');/**（销量6） (erp近30天销售量（品类）) **/
            $schedule->command('sr:msv')->dailyAt('08:41')->runInBackground()->description('svMonthly'); /**（销量7） (erp近14个月销售量)(更新月销量目标) **/
            //销售额统计报表（ERP）
            $schedule->command('sr:cdsa')->dailyAt('08:46')->runInBackground()->description('csaDaily'); /**（销量8） (erp日销售额) **/    /*------（按天统计金额 erp）------**/
            $schedule->command('sr:dsa')->dailyAt('08:51')->runInBackground()->description('saDaily');   /**（销量9） (erp近30天销售额) **/
            $schedule->command('sr:msa')->dailyAt('08:56')->runInBackground()->description('saMonthly'); /**（销量10）(erp近14个月销售额) **/

            //产品毛利率
            $schedule->command('profit-sku:sync')->dailyAt('00:35')->runInBackground()->description('syncProfitSku');
            $schedule->command('profit-sku:seller')->dailyAt('01:35')->runInBackground()->description('syncSeller');
            $schedule->command('profit-sku:sale-price')->dailyAt('01:45')->runInBackground()->description('syncSalePrice');

            //更新产品毛利率表FBA费（每周2-6）
            $schedule->command('profit-sku:fba-fee-daily')->cron('50 2 * * 2-6')->runInBackground()->description('syncFBAFeeDaily');
            //Weekly
            //更新产品毛利率表FBA费
            $schedule->command('profit-sku:fba-fee')->cron('10 1 * * 7')->runInBackground()->description('syncFBAFee');
            //更新产品毛利率表退货率
            $schedule->command('profit-sku:return')->cron('50 1 * * 7')->runInBackground()->description('syncReturn');
            //Monthly
            //更新产品毛利率表物流费
            $schedule->command('profit-sku:logistics')->cron('20 1 13 * *')->runInBackground()->description('syncLogistics');


            //（EU）（EU国家的备货提货基础）
            //（EU）更新,EU国家的基础品类/sku预估月份
            $schedule->command('country:estimate')->monthlyOn(1, '01:00')->runInBackground()->description('CountryEstimate'); //每月1号
            //（EU）创建/同步,EU国家的基础sku
            $schedule->command('country:sync-ss')->dailyAt('02:00')->runInBackground()->description('CountrySyncSS');
            //（EU）更新,EU国家的基础sku销量均值
            $schedule->command('country:avg')->dailyAt('03:00')->runInBackground()->description('CountryAvg');  /**（销量12）**/
            //（EU）更新,EU国家的备货sku
            $schedule->command('country:ss')->dailyAt('04:00')->runInBackground()->description('CountrySS'); //每日
            //（EU）更新,EU国家的非FBA库存（国内、海外仓库存）
            $schedule->command('country:not-fba-stock')->everyFiveMinutes()->runInBackground()->description('CountryNotFBAStock'); //30分钟
            ////已移至自定义命令-手动运行
            //（EU）更新,EU国家的sku-FBA库存（FBA库存）
            //$schedule->command('country:fba-stock')->dailyAt('08:00')->runInBackground()->description('CountryFBAStock'); //每日

            //（JP）（JP平台的备货提货基础）
            //（JP）更新,JP平台的基础品类/sku预估月份
            $schedule->command('jp:estimate')->monthlyOn(1, '01:20')->runInBackground()->description('JpEstimate'); //每月1号
            //（JP）创建/同步,JP平台的基础sku
            $schedule->command('jp:sync-ss')->dailyAt('02:20')->runInBackground()->description('JpSyncSS');
            //（JP）更新,JP平台的基础sku销量均值
            $schedule->command('jp:avg')->dailyAt('03:20')->runInBackground()->description('JpAvg');            /**（销量13）**/
            //（JP）更新,JP平台的备货sku
            $schedule->command('jp:ss')->dailyAt('04:20')->runInBackground()->description('JpSS'); //每日
            //（JP）更新,JP平台的非FBA库存（国内、海外仓库存）
            $schedule->command('jp:not-fba-stock')->everyFiveMinutes()->runInBackground()->description('JpNotFBAStock'); //1小时
            ////已移至自定义命令-手动运行
            //（JP）更新,基础JP平台的sku-FBA库存（FBA库存）
            //$schedule->command('jp:fba-stock')->dailyAt('08:20')->runInBackground()->description('JpFBAStock'); //每日

            //（总）（站点的备货提货基础）
            //（总） 站点的基础品类/sku预估月份
            $schedule->command('ss:estimate')->monthlyOn(1, '01:40')->runInBackground()->description('syncEstimate'); //每月1号
            //（总）（站点）创建/同步,站点的基础sku
            $schedule->command('dss:sync')->dailyAt('08:20')->runInBackground()->description('syncSS');
            //（总）（站点）更新,站点的基础sku销量均值
            $schedule->command('dss:avg')->dailyAt('08:30')->runInBackground()->description('syncAVG');         /**（销量11）**/
            //（总）（站点）更新,站点的备货sku、提货sku
            $schedule->command('dss:basic')->dailyAt('08:55')->runInBackground()->description('initSSBasic');
            //（总）（站点）更新,站点的非FBA库存（国内、海外仓库存）
            $schedule->command('ss:not-fba-stock')->everyFiveMinutes()->runInBackground()->description('syncNotFBAStock')->withoutOverlapping();


            //提货状态
            $schedule->command('ssku:sync-status')->dailyAt('23:10')->runInBackground()->description('syncSSkuStatus');
            $schedule->command('stotal:sync-differ')->dailyAt('23:25')->runInBackground()->description('syncTotalDiffer');

            //备货设置日期
            $schedule->command('stocking:sync-set-date')->dailyAt('01:20')->runInBackground()->description('syncStockingSetDate');
            $schedule->command('stocking:init-set-date')->dailyAt('01:50')->runInBackground()->description('initStockingSetDate');

            //更新月利润表-品类销售
            $schedule->command('sr:sync-seller')->dailyAt('02:20')->runInBackground()->description('syncSeller');

            //抓取星级，大小类排名
            $schedule->command('operation:crawl-star')->dailyAt('20:35')->runInBackground()->description('crawlStar');

            //运单号异常 (中国发FBA)
            $schedule->command('logistics:track-ex-cn')->dailyAt('20:45')->runInBackground()->description('dLTrackExCheck');
            //运单号异常 (中国发海外仓)(中转和代发)
            $schedule->command('logistics:track-ex-os')->dailyAt('20:50')->runInBackground()->description('osLTrackExCheck');
            $schedule->command('logistics:track-ex-os-dropshipping')->dailyAt('20:55')->runInBackground()->description('osLTrackExCheck');

            //到货异常-FBA (中国发FBA、海外仓中转发FBA、海外仓移库发FBA)
            $schedule->command('fulfillment:ex-cn')->dailyAt('21:05')->runInBackground()->description('lFulfillmentCheck');
            $schedule->command('fulfillment:ex-os-fba')->dailyAt('21:10')->runInBackground()->description('lFBAFulfillmentCheck');
            $schedule->command('fulfillment:ex-os-removale')->dailyAt('21:15')->runInBackground()->description('lRemovaleFulfillmentCheck');
            //到货异常-海外仓 (中国发海外仓中转、中国发海外仓代发)
            $schedule->command('receive:ex-os-in')->dailyAt('21:20')->runInBackground()->description('receiveExCheck');
            $schedule->command('receive:ex-os-in-dropshipping')->dailyAt('21:25')->runInBackground()->description('receiveExCheck');

        //定时清空日志记录
            $schedule->command('logs:truncate')->cron('1 0 2 * *')->runInBackground()->description('truncateLogs');

         //Daily
            //运营总表-广告
            $schedule->command('check:operation-ads')->dailyAt('16:25')->runInBackground()->description('CheckOperationAds');
            //运营总表-星级
            $schedule->command('check:operation-star')->dailyAt('17:00')->runInBackground()->description('CheckOperationStar');
            //运营总表-business
            $schedule->command('check:operation-business')->dailyAt('17:25')->runInBackground()->description('CheckBusinessOperation');


            //库存汇总
            //库存总表（SKU）
            $schedule->command('inventory:sync-inventory-sku')->everyTenMinutes()->runInBackground()->description('syncInventorySku'); //1小时
            //库存总表（站点）
            $schedule->command('inventory:sync-inventory-area')->everyTenMinutes()->runInBackground()->description('syncInventoryArea'); //1小时
            //库存总表（站点FBA库存）
            $schedule->command('inventory:sync-inventory-area-fba')->everyTenMinutes()->runInBackground()->description('syncInventoryAreaFba'); //1小时
            //库存总表（站点非FBA库存）
            $schedule->command('inventory:sync-inventory-area-no-fba')->everyTenMinutes()->runInBackground()->description('syncInventoryAreaNoFba'); //1小时

            $schedule->command('inventory:dis-temp')->everyMinute()->runInBackground()->description('DisTempInventory'); //1分钟

            ////从shopifyAPI平台同步订单至后台shopify基础数据库
            //$schedule->command('shopify-api:get-orders')->cron('*/5 * * * *')->runInBackground()
            //   ->description('shopifyOrderGetOrders')->withoutOverlapping();

            ////从rakutenAPI平台同步订单至后台rakuten基础数据库
            //$schedule->command('rakuten-api:get-orders')->cron('*/5 * * * *')->runInBackground()
            //   ->description('rakutenOrderGetOrders')->withoutOverlapping();

        }
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
